package com.example.view.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Scroller;

import androidx.annotation.Nullable;

import com.example.common.utils.L;

public class MyImageView extends androidx.appcompat.widget.AppCompatImageView {

    private Scroller scroller;

    public MyImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.scroller = new Scroller(context);
    }

    @Override
    public void computeScroll() {
        super.computeScroll();
        if (scroller.computeScrollOffset()) {   //滑动还没有完成
            L.e("MyImageView", "CurrX=" + scroller.getCurrX());
            scrollTo(scroller.getCurrX(), scroller.getCurrY());
            invalidate();
        }
    }

    public void reset() {
        scroller.startScroll(getScrollX(), getScrollY(), -getScrollX(), -getScrollY(), 1000);
        invalidate();
    }
}
